﻿Imports System.Data.OleDb

Public Class Details
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then Return
        'Meaning if it is a post back then we jump'
        'out of the function and does not run the rest below'
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim sql = "INSERT INTO CarsViewedByUsers (CarFkId,OwnerName) Values(@f1,@f2)"
        Dim cmd = New OleDbCommand(sql, conn)
        conn.Open()
        cmd.Parameters.AddWithValue("@f1", Request.Params("CarID"))
        cmd.Parameters.AddWithValue("@f2", User.Identity.Name)
        cmd.ExecuteNonQuery()
        conn.Close()
    End Sub

    Protected Sub btnComment_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnComment.Click
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim sql = "INSERT INTO Car_Comments(Author,Title,Message,CarID) VALUES(@f1,@f2,@f3,@f4)"
        Dim cmd = New OleDbCommand(sql, conn)
        conn.Open()
        cmd.Parameters.AddWithValue("@f1", txtName.Text)
        cmd.Parameters.AddWithValue("@f2", txtTitle.Text)
        cmd.Parameters.AddWithValue("@f3", txtMessage.Text)
        cmd.Parameters.AddWithValue("@f4", Request.Params("CarID"))
        cmd.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("Details.aspx?CarID=" & Request.Params("CarID"))

    End Sub
  
End Class